package com.snj.visangedu.video;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.VideoView;

import com.snj.visangedu.Activity_QSend;
import com.snj.visangedu.R;

public class VideoActivity extends Activity implements OnClickListener {
	
	VideoView video_videoview = null;
	Button btn_q = null;
	
	String videoid = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_video);
		
		Intent intent = getIntent();
		videoid = intent.getStringExtra("videoid");
		
		video_videoview = (VideoView)findViewById(R.id.video_videoview);
		btn_q = (Button)findViewById(R.id.btn_q);
		btn_q.setOnClickListener(this);
		
		
	}
	
	
	
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		
		MediaController mediaController = new MediaController(getApplicationContext());
		
		mediaController.setAnchorView(video_videoview);
		
		Uri video = Uri.parse("http://viewnpop.com/snj/visangedu/videos/" + videoid + ".mp4");
		
		//video_videoview.setMediaController(mediaController);
		
		video_videoview.setVideoURI(video);
		//video_videoview.setOnPreparedListener(PreparedListener);
		video_videoview.requestFocus();
		
		video_videoview.start();
		
	}




	MediaPlayer.OnPreparedListener PreparedListener = new OnPreparedListener() {
		
		@Override
		public void onPrepared(MediaPlayer m) {
			// TODO Auto-generated method stub
			
			try {
                if (m.isPlaying()) {
                    m.stop();
                    m.release();
                    m = new MediaPlayer();
                }
                
                //m.setOnVideoSizeChangedListener(onVideoSizeChangedListener);  
                
                //LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,  
              //ViewGroup.LayoutParams.FILL_PARENT);  
                //menu3_videoview.setLayoutParams(lp);
                //menu3_videoview.setMediaController(null);
                
                //m.setVolume(0f, 0f);
                //m.setLooping(false);
                m.start();
            } catch (Exception e) {
                e.printStackTrace();
            }   
		}
	};

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		switch(v.getId())
		{
		case R.id.btn_q:
			
			Intent intent = new Intent(getApplicationContext(), Activity_QSend.class);
			startActivity(intent);
			
			break;
		}
		
	}
}
